#!/bin/sh
# This regression test is a part of SIPp.
# A 200 with an SRTP answer that goes to _unexp.main has its SDP read
# once: read again, it counts as an offer, the UAC's re-INVITE as an
# answer and the peer's answer as an offer, so the UAC keeps sending
# with its first line and not the answered AES_CM_128_HMAC_SHA1_32 one.
# The UAC exits with 253 if the echoed RTP does not match.
. "`dirname "$0"`/../functions"; init

sippbg -sf uas.xml -i 127.0.0.1 -p 30700 -m 1 \
    -min_rtp_port 30710 -max_rtp_port 30719 -timeout 10
uas=$pid
sippfg -sf uac.xml -i 127.0.0.1 -p 30701 -m 1 \
    -min_rtp_port 30720 -max_rtp_port 30729 \
    127.0.0.1:30700 -timeout 10 >/dev/null 2>&1
status=$?
wait $uas
uas_status=$?

if test $status -eq 253; then
    fail "the UAC did not get its media echoed back"
elif test $status -ne 0; then
    fail "the UAC failed with $status"
elif test $uas_status -ne 0; then
    fail "the UAS failed with $uas_status"
else
    ok
fi
